<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;

class UserController extends Controller {
	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
    public  function index(Request $request){
        $paginate=10;
        if($request->has('paginate')){
            $paginate=$request->get('paginate');
        }     
        $query=User::orderBy('createTime','desc');
        if($request->has('offlineid')){
            $offlineId=$request->get('offlineid');
            $query->where('offlineId', $offlineId);
        }
        if($request->has('name')){
            $name=$request->get('name');
            $query->where('name','like','%'.$name.'%');
        }
         if($request->has('nick')){
            $nick=$request->get('nick');
            $query->where('nick','like','%'.$nick.'%');
        }
        if($request->has('type')){
            $type=$request->get('type');
            $query->where('type',$type);
        }
        if($request->has('usable')){
            $usable=$request->get('usable');
            $query->where('usable',$usable);
        }
        if($request->has('date')){
            $date=$request->get('date');
            $createTime1=$date[0];
            $createTime1=date("Y-m-d 00:00:00", strtotime($createTime1));
            $createTime2=$date[1];
            $createTime2=date("Y-m-d 23:59:59", strtotime($createTime2));
            $query->where('createTime','>=',$createTime1)->where('createTime','<=',$createTime2);
        }
//        file_put_contents('1.txt', $createTime1);
//      file_put_contents('2.txt', $createTime2);

//        if($request->has('date1')){
//            $createTime1=$request->get('date1');
//            $createTime2=$request->get('date2');
//            $query->where('createTime','>',$createTime1)->where('createTime','<',$createTime2);
//        }
        
        if($request->has('quanbu')){//如果是全部则不需要分页 说明不是用户列表  是所有的骑手列表或拣货员列表
           $data=$query->get();
        return response()->json(['data'=>$data]);
        }else{
          $data=$query->paginate($paginate);
        return $data;
         }
          }
          
          
    public  function user(Request $request){
         $query=User::orderBy('createTime','desc');
      
        if($request->has('offlineid')){
            $offlineId=$request->get('offlineid');
            $query->where('offlineId', $offlineId);
        }
        if($request->has('name')){
            $name=$request->get('name');
            $query->where('name','like','%'.$name.'%');
        }
        if($request->has('type')){
            $type=$request->get('type');
            $query->where('type',$type);
        }
        if($request->has('usable')){
            $usable=$request->get('usable');
            $query->where('usable',$usable);
        }
        if($request->has('date1')){
            $createTime1=$request->get('date1');
            $createTime2=$request->get('date2');
            $query->where('createTime','>',$createTime1)->where('createTime','<',$createTime2);
        }
          $data=$query->get();
        return response()->json(['data'=>$data]);
          }
}
